import Vue from "vue"
import Vuex from "vuex"
import axios from "axios"
Vue.use(Vuex)
export default new Vuex.Store({
    state: {
        data: [],
        datas: [],
        list: [],
        lists: [],
        shops: [],
        caipu: [],
        zhouji: [],
        xiang: null,
        bancheng: [],
        banxiang: null,
        shuiguo: [],
        shuiguoxiang: []
    },
    mutations: {
        async datas(state, data) {
            await axios.post("/api/get_dishes", { id: data }).then(res => {
                state.data = res.data
            })
        },
        async lists(state, data) {
            axios.post("/api/get_chef", { id: data }).then(res => {
                state.list = res.data;
            })
        },
        async items(state, data) {
            await axios.post('/api/get_gai', data).then(res => {
                state.list = res.data
            })
        },
        async loginBtn(state, data) {
            await axios.post("/api/get", data).then(res => {
                state.loginData = res.data
            })
        },
        async datasa(state, data) {
            await axios.post("/api/data", { id: data }).then(res => {
                state.datas = res.data
            })
        },
        async listsa(state, data) {
            await axios.post("/api/list", { id: data }).then(res => {
                state.lists = res.data;
            })
        },
        async canpus(state, data) {
            await axios.post("/api/canpus").then(res => {
                state.caipu = res.data
                state.zhouji = res.data.filter(item => {
                    return item.ids == data
                })
            })
        },
        canpusa(state, data) {
            state.zhouji = state.caipu.filter(item => {
                return item.ids == data
            })
        },
        xiangs(state, data) {
            state.xiang = state.caipu.find(item => {
                return item.id == data
            })
        },
        async bancheng(state, data) {
            await axios.post("/api/banchen").then(res => {
                state.bancheng = res.data
            })
        },
        cheng(state, data) {
            let xiang = state.bancheng.find(item => {
                return item.id == data.id
            })
            xiang.juti = data.juti
            state.banxiang = xiang
            console.log(state.banxiang)
        },
        async shuiguo(state, data) {
            await axios.post("/api/shuiguo").then(res => {
                state.shuiguo = res.data
                state.shuiguoxiang = res.data.filter(item => {
                    if (data === 0) {
                        return item.flag === "true"
                    } else {
                        return item.ids == data
                    }
                })
            })
        },
        shuiguoxiang(state, data) {
            state.shuiguoxiang = state.shuiguo.filter(item => {
                if (data === 0) {
                    return item.flag === "true"
                } else {
                    return item.ids == data
                }
            })
        },
    }
})